package org.oschina.api.manage.module.dao;

import java.util.List;

import org.oschina.Constants;
import org.oschina.api.BaseDAO;
import org.oschina.api.manage.module.vo.ModuleVo;
import org.springframework.stereotype.Repository;

@Repository
public class ModuleDAO extends BaseDAO {

	private final String find[]={"id","name","type"};
	private final String findVo[]={"id","name","type"};
	
	/**
	 * 根据类型返回
	 * @param type
	 * @return
	 */
	public List<ModuleVo> findVoByType(int type)
	{
		return getQueryHelper().query_cache(findVo,new String[]{"type=?"}, new String[]{"ORDER BY id"}, new Object[]{type}, ModuleVo.class, -1,-1);
	}
	
	/**
	 * 根据ID返回
	 * @param id
	 * @return
	 */
	public ModuleVo _findVoById(int id)
	{
		ModuleVo moduleVo=(ModuleVo) getCacheHelper().hget(getKey(Constants.CACHE_MODULE,id), ModuleVo.class);
		if(moduleVo!=null)
			return moduleVo;
		
		return _findById(id);
	}
	private ModuleVo _findById(int id)
	{
		return (ModuleVo) getQueryHelper().queryForObject_cache(findVo, new String[]{"id=?"}, new Object[]{id}, ModuleVo.class);
	}
}